import { Component } from 'react';
import './SearchData.less'

export default class SearchData extends Component {

  constructor(props) {
    super(props);
    this.state = {
      data: this.props.data || [],
      realData: this.props.realData || []
    }
  }

  static defaultProps = {

  }
  static propTypes = {

  }

  handleAction(key) {
    let { state: { realData } } = this;
    this.props.action(realData[key]);
  }

  render() {
    let { state: { data }, handleAction } = this;
    let jsx = null;
    if (data.length) {
      jsx = data.map((l, k) => (<p key={k} onClick={handleAction.bind(this, k)}>{`${l}`}</p>));
    }
    return (
      <div className="mod-search-data">
        <div className="search-result">
          <h3>匹配的线路信息:</h3>
          <div>{jsx}</div>
        </div>
      </div>
    );
  }
  componentWillReceiveProps(nextProps) {
    this.setState({ data: nextProps.data, realData: nextProps.realData });
  }
}